/**
 * This is for Cross-site Origin Resource Sharing (CORS) requests.
 *
 * Additionally the script will fail-over to a proxy if you have one set up.
 *
 * @param string   url      the url to retrieve
 * @param mixed    data     data to send along with the get request [optional]
 * @param function callback function to call on successful result [optional]
 * @param string   type     the type of data to be returned [optional]
 */

function getCORS(url, data, callback, type) {


    if (typeof crossdomain == "undefined") {
        // Try using jQuery to get data
        
        $.get(url, data, callback, type);
    } 
    else{
            
      //  // jQuery get() failed, try IE8 CORS, or use the proxy
//        if (jQuery.browser.msie && window.XDomainRequest) {
            // Use Microsoft XDR
//                    var params = 'test=1';
                  //  alert(params);
//                    if(is_string(data))
//                    {
//                    params=data;
//                    }else
//                    {
//                     
//                    for (key in data) {
//                    params = params+'&'+key+'='+data[key];
//                    }
//                    
//                    }
                  //  alert(params);
//                    
//                    
//            var httpRequest  = new XDomainRequest();
//            httpRequest.onload = function() {
//                callback(httpRequest.responseText, 'success');
//            }; 
//            httpRequest.onprogress = function () {
                //alert("XDR onprogress"); 
//                };   
//            httpRequest.onerror  = function() {
              //  alert('Error');
//            }; 
           // httpRequest.timeout = 3200;
//            
//            httpRequest.open("get", url+'?'+params);
//            httpRequest.send(); 
            
            


           
       // } 
//        else {
//              jQuery.get(url, data, callback, type);   
//        }
    }
}

/**
 * This method is for Cross-site Origin Resource Sharing (CORS) POSTs
 *
 * @param string   url      the url to post to
 * @param mixed    data     additional data to send [optional]
 * @param function callback a function to call on success [optional]
 * @param string   type     the type of data to be returned [optional]
 */
function postCORS(url, data, callback, type)
{
    
    if(typeof crossdomain == "undefined") {
        // Try using jQuery to POST
        $.post(url, data, callback, type);
    } else {
      //  // jQuery POST failed

        // Try XDR, or use the proxy
//        
//        if (jQuery.browser.msie && window.XDomainRequest) {
            // Use XDR
//            var params = 'test=1';
                  //  alert(params);
//                    if(is_string(data))
//                    {
//                    params=data;
//                    }else
//                    {
//                     
//                    for (key in data) {
//                    params = params+'&'+key+'='+data[key];
//                    }
//                    
//                    }
//            var httpRequest  = new XDomainRequest();
//            httpRequest.onload = function() {
//                callback(httpRequest.responseText, 'success');
//            }; 
//            httpRequest.onprogress = function () {
                //alert("XDR onprogress"); 
//                };   
//            httpRequest.onerror  = function() {
              //  alert('Error');
//            }; 
           // httpRequest.timeout = 3200;
//            
//            httpRequest.open("post", url);
//            httpRequest.send(params); 
//        
//        } 
//        else {

//           jQuery.post(url, data, callback, type);
//        }
    }
}
 function validateEmail(email) { 
  // http://stackoverflow.com/a/46181/11236
  
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}
function loadsave()
{
    $.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .5, 
            color: '#fff' 
        } }); 
}
function loadclosesave()
{
  $.unblockUI();
}
function logout()
{

       
       getCORS(serviceinfo+'logout',{} ,function(data) {
       
       if(data.error)
       {
          alert(data.error);
       
       }else
       {
          location.href=baseinfo+"/login";
       
       } 
       
       });

}
